package com.seven.dao;

import java.util.List;

import com.seven.entity.Users;

//普通用户dao
public class UsersDao extends BaseDao {
	/**
	 * 添加用户
	 */
	public int addUsers(Users users) {
		String sql = "insert into users(users_name,users_username,users_password,users_score)values(?,?,?,?)";
		Object[] ob = {users.getUsers_name(),users.getUsers_username(),users.getUsers_password(),users.getUsers_score()};
		int n = super.update(sql, ob);
		return n;

	}

	/**
	 * 更新用户
	 */
	public int updateUsers(Users users) {
		String sql = "update users set users_name = ?,users_username = ?,users_password = ?,users_score = ? where users_id=?";
		Object[] ob = {users.getUsers_name(),users.getUsers_username(),users.getUsers_password(),users.getUsers_score(),users.getUsers_id()};
		int n = super.update(sql, ob);
		return n;

	}

	/**
	 * 查询所有用户
	 */
	public List<Users> selectAllUsers() {
		
		String sql = "select * from users";
		return super.query2(sql, Users.class);
		
		
	}
	
	/**
	 * 通过id查找用户
	 */
	public List<Users> selectById(int id) {
		
		String sql = "select * from users where users_id = ?";
		int ob = id;
		return super.query2(sql, Users.class,ob);
		
		
	}

	/**
	 * 通过账号查询用户
	 */
	public List<Users> selectByUsers_username(Users users) {
		String sql = "select * from users where users_username=? and users_password = ?";
		Object[] ob = {users.getUsers_name(),users.getUsers_password()};
		return super.query2(sql, Users.class, ob);
	}
	
	/**
	 * 通过id查姓名
	 */
	public List<Users> selectNameById(int users_id) {
		String sql = "select * from users where users_id=?";
		int ob = users_id;
		return super.query2(sql, Users.class, ob);
	}

}
